﻿Option Explicit On
Option Strict On

Imports LogginsLogDSTableAdapters

Partial Class private_secure_members_RegComplete
    Inherits System.Web.UI.Page
    Dim u As MembershipUser
    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        'If Not Page.PreviousPage Is Nothing Then
        '    Dim SourceTextBox As Label
        '    SourceTextBox = CType(PreviousPage.FindControl("lblUserName"), Label)

        '    If Not SourceTextBox Is Nothing Then
        '        Label1.Text = SourceTextBox.Text
        '        Dim personTA As New PersonTableAdapter()
        '        Dim personDT As LogginsLogDS.PersonDataTable
        '        u = Membership.GetUser(SourceTextBox)
        '        personDT = personTA.GetData(u.ProviderUserKey)
        '        If personDT.Rows.Count > 0 Then
        '            Response.Write(personDT.Rows.Count.ToString())
        '        End If
        '    Else
        '        Response.Redirect("~/Account/Login.aspx")
        '    End If
        'End If

        If User.Identity.IsAuthenticated Then
            u = Membership.GetUser(User.Identity.Name)
            'txtGuid.Text = u.ProviderUserKey.ToString()
            'ElseIf Not Session("UserName1") Is Nothing Then
            '    u = Membership.GetUser(Session("UserName1").ToString())
            '    'txtGuid.Text = u.ProviderUserKey.ToString()
            Dim ContactEmail As TextBox = CType(Me.FormView1.FindControl("txtContactEmail"), TextBox)
            Dim ReportEmail As TextBox = CType(Me.FormView1.FindControl("txtReportEmail"), TextBox)
            ContactEmail.Text = u.Email
            ReportEmail.Text = u.Email

        Else
            Response.Redirect("~/private/default.aspx")
        End If

    End Sub

    Protected Sub ObjectDataSource1_Updated(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ObjectDataSource1.Updated

        Dim strMailFrom As String = ConfigurationManager.AppSettings("smtpmailfrom").ToString()
        Dim strMailTo As String = ConfigurationManager.AppSettings("accountapprovalemail").ToString()

        Dim virtualurl As String = ("http://" + HttpContext.Current.Request.Url.Authority.ToString() + "/" + _
            HttpContext.Current.Request.Url.Segments(1).ToString() + "private/secure_admin/default.aspx?id=").Replace("/Private/Private", "/Private") 'Tony Added

        Dim sendemail As New SendEmailViaGoogle()
        Dim userchectregistrationcompleteTA As New SPTableAdapter
        Try
            sendemail.SendEmail(strMailFrom, strMailTo, "Account Approval Request", "Please approve this user's account   " + virtualurl + u.ProviderUserKey.ToString())
            userchectregistrationcompleteTA.usp_UpdateUserCheckRegistrationComplete(CType(u.ProviderUserKey, Global.System.Guid?))
            Response.Redirect("~/private/default.aspx")

        Catch ex As Exception
            Throw ex
        End Try

    End Sub

    Protected Sub ObjectDataSource1_Selecting(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) Handles ObjectDataSource1.Selecting
        If Not u.ProviderUserKey Is Nothing Then
            e.InputParameters("UserId") = u.ProviderUserKey
        Else
            Response.Redirect("~/private/default.aspx")
        End If

    End Sub

End Class
